<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>从服务端检回一个元素</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="memcache.flush.html">Memcache::flush</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="memcache.getextendedstats.html">Memcache::getExtendedStats</a></div>
 <div class="up"><a href="class.memcache.html">Memcache</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="memcache.get" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Memcache::get</h1>
  <p class="verinfo">(PECL memcache &gt;= 0.2.0)</p><p class="refpurpose"><span class="refname">Memcache::get</span> &mdash; <span class="dc-title">从服务端检回一个元素</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-memcache.get-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>Memcache::get</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$flags</code></span>
  ] )</div>

  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>Memcache::get</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$keys</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$flags</code></span>
  ] )</div>

  
  <p class="para rdfs-comment">
   如果服务端之前有以<em><code class="parameter">key</code></em>作为key存储的元素，<span class="function"><strong>Memcache::get()</strong></span>方法此时返回之前存储的值。
  </p>

  <p class="para">
  你可以给<span class="function"><strong>Memcache::get()</strong></span>方法传递一个数组（多个key）来获取一个数组的元素值，返回的数组仅仅包含从
  服务端查找到的key-value对。
  </p>
  
 </div>

  
 <div class="refsect1 parameters" id="refsect1-memcache.get-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">key</code></em></dt>

     <dd>

      <p class="para">
       要获取值的key或key数组。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">flags</code></em></dt>

     <dd>

      <p class="para">
      如果给定这个参数（以引用方式传递），该参数会被写入一些key对应的信息。这些标记和<span class="function"><a href="memcache.set.html" class="function">Memcache::set()</a></span>方法中的同名参数
      意义相同。用int值的低位保留了pecl/memcache的内部用法（比如：用来说明压缩和序列化状态）。（译注：最后一位表明是否序列化，倒数第二位表明是否经过压缩， 
      比如：如果此值为1表示经过序列化，但未经过压缩，2表明压缩而未序列化，3表明压缩并且序列化，0表明未经过压缩和序列化，具体算法可查找linux文件权限算法相关资料）
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-memcache.get-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
  返回<em><code class="parameter">key</code></em>对应的存储元素的字符串值或者在失败或<em><code class="parameter">key</code></em>未找到的时候返回<strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-memcache.get-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4322">
    <p><strong>Example #1 <span class="function"><strong>Memcache::get()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;procedural&nbsp;API&nbsp;*/<br /></span><span style="color: #0000BB">$memcache_obj&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">memcache_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$var&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">memcache_get</span><span style="color: #007700">(</span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'some_key'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;OO&nbsp;API&nbsp;*/<br /></span><span style="color: #0000BB">$memcache_obj&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Memcache</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$var&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(</span><span style="color: #DD0000">'some_key'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;<br />你同样可以使用数组key作为参数，如果某个元素没有在服务端发现，结果数组中将不会包含这些key。<br />*/<br /><br />/*&nbsp;procedural&nbsp;API&nbsp;*/<br /></span><span style="color: #0000BB">$memcache_obj&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">memcache_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$var&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">memcache_get</span><span style="color: #007700">(</span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">,&nbsp;Array(</span><span style="color: #DD0000">'some_key'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'another_key'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;OO&nbsp;API&nbsp;*/<br /></span><span style="color: #0000BB">$memcache_obj&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Memcache</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'memcache_host'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$var&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$memcache_obj</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get</span><span style="color: #007700">(Array(</span><span style="color: #DD0000">'some_key'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'second_key'</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="memcache.flush.html">Memcache::flush</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="memcache.getextendedstats.html">Memcache::getExtendedStats</a></div>
 <div class="up"><a href="class.memcache.html">Memcache</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
